package de.game;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;

import android.content.Context;
import android.content.ContextWrapper;
import android.util.Log;

import de.game.activities.GameActivity;


public class SaveData implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2280297916977442772L;
	private static Context con;
	
	public SaveData(Context myContext){
		con = myContext;
	}
	
//	public static void save(){
//		
//		FileOutputStream fos = null;
//		ObjectOutputStream out = null;
//		
//		
//		try
//		    {
//		       fos = new FileOutputStream("Level.dat");
//		       out = new ObjectOutputStream(fos);
//		       out.writeObject(LabPanel.getLevels());
//		       out.close();
//	 
//	}
//		catch(IOException ex)
//		    {
//		      ex.printStackTrace();
//		     }	
//	}
	
	
	
	
	@SuppressWarnings("unchecked")
	public static void load(){
		ArrayList<Level> templevels = new ArrayList<Level>();
		InputStream fis = null;
		ObjectInputStream in = null;
		
		   try
		  { 
			   
			fis = con.getAssets().open("levels/Level.dat");
			in = new ObjectInputStream(fis);
			   templevels = (ArrayList<Level>) in.readObject();			 
			   in.close();   
			   GameEngine.setLevels(templevels);

		  }
		   catch(FileNotFoundException ex)
			  {
			     System.out.println("file not found");
			  }
		  catch(IOException ex)
		  {
		     ex.printStackTrace();
		  }
		  catch(ClassNotFoundException ex)
		  {
		    ex.printStackTrace();
		  }
		
	}

	
	
}
